﻿using System;
using System.Windows.Forms;
using CefSharp;

namespace WebVideoCollector.Form
{
    public partial class ContainerForm : System.Windows.Forms.Form
    {
        private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(ContainerForm));

        private MainForm _form;

        public ContainerForm()
        {
            Log.Debug("启动");
            InitializeComponent();
            Program.ContainerForm = this;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DoLogin();
        }

        private void DoLogin()
        {
            this.button1.Enabled = false;
            this.panel2.Controls.Clear();
            _form = new MainForm();
            _form.MdiParent = this; //指定当前窗体为顶级Mdi窗体
            _form.Parent = this.panel2; //指定子窗体的父容器为
            _form.FormBorderStyle = FormBorderStyle.None; //隐藏子窗体边框，当然也可以在子窗体的窗体加载事件中实现
            _form.Show();
        }

        private void ContainerForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            Cef.Shutdown();
            Environment.Exit(0);
        }

        private void btnHide_Click(object sender, EventArgs e)
        {
            this.panel2.Visible = !this.panel2.Visible;
        }
    }
}